package trainingcamp.day02.char_api;

public class 字符串API交换文字顺序练习 {
    public static void main(String[] args) {

        //
        String str = "学校一共有20个人,其中x生15,老师是5";
        char[] newstr = new char[str.length()];
        char min = '\u4E00';
        char max = '\u9FA5';
        for (int i = 1; i< str.length();i+=2){

            char before = str.charAt(i-1);
            char after = str.charAt(i);
            if((min<=before && before<=max) &&
                    (min<=after && after<=max)){
                newstr[i-1] = after;
                newstr[i] = before;
            }else{
                newstr[i-1] = before;
                newstr[i] = after;
            }
            if(str.length()%2 != 0){
                newstr[newstr.length-1] = str.charAt(str.length()-1);
            }
        }
        System.out.println(str);
        System.out.println(newstr);

    }


}
